<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>投票页面</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <#assign currentMenu="activity"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>投票页面</h1>
        </section>
        <section class="content">
            <div class="box" style="padding: 10px">
                <div class="row">
                    <div class="col-md-offset-4 col-md-8">
                        <h1>${activity.title}</h1>
                    </div>
                    <div class="col-md-8">
                        <div class="panel panel-default container">
                            <div class="panel-body">
                                <form id="editForm" action="/activity/increaseNum" method="post">
                                    <input type="hidden" value="${activity.id}" name="activityId">
                                    <#if activity.type == 1>
                                        <#list activity.activityItems as a>
                                            <div class="row">
                                                <div class="col-md-2">
                                                    <div class="checkbox">
                                                        <label>
                                                            <input type="checkbox" name="itemIds" value="${a.id}"> ${a_index + 1}.${a.content}
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                        </#list>
                                    <#else>
                                        <#list activity.activityItems as a>
                                            <div class="row">
                                                <div class="col-md-2">
                                                    <div class="radio">
                                                        <label>
                                                            <input type="radio" name="itemIds" value="${a.id}"> ${a_index + 1}.${a.content}
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>
                                        </#list>
                                    </#if>
                                    <a href="javascript:window.history.back()" class="btn btn-default">取消</a>
                                    <button type="button" class="btn btn-primary btn-submit btn-showActivity">提交</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>
<script>
    $(function () {
        $(".btn-showActivity").click(function () {
            Swal.fire({
                title : "确定投票吗?",
                icon : "info",
                showCancelButton :true,
                cancelButtonText :"取消",
                confirmButtonText:"确定"
            }).then((result)=>{
                if(result.value){
                    $("#editForm").ajaxSubmit(function (data) {
                        console.log(data);
                        if(data.success){
                            window.location.href = "/activity/show?id=" + ${activity.id};
                        }else{
                            Swal.fire({
                                title : data.msg,
                                icon : "warning",
                            });
                        }
                    });
                }
            });
        });
    });
</script>
</body>
</html>
